<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="供应商代码">
              <a-input placeholder="请输入供应商代码" v-model.trim="queryParam.code"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="供应商名称">
              <a-input placeholder="请输入供应商名称" v-model.trim="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="经营类目">
              <a-tree-select
                v-model="queryParam.categoryId"
                :replaceFields="replaceFields"
                :filterTreeNode="filterTreeNode"
                show-search
                style="width: 100%"
                :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
                :tree-data="treeData"
                placeholder="请选择经营类目"
                tree-default-expand-all
                :getPopupContainer="node => node.parentNode"
              >
              </a-tree-select>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="付款方式">
                <j-search-select-tag placeholder="请选择付款方式" v-model="queryParam.paymentMethod" dict="product_supplier_payment_method"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="采购员">
                <j-search-select-user v-model="queryParam.buyer" placeholder="请输入并选择采购员"></j-search-select-user>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="状态">
                <j-dict-select-tag type="list" v-model="queryParam.supplierStatus" dictCode="product_supplier_status" placeholder="请选择状态" />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="创建人">
                <j-search-select-user v-model="queryParam.createBy" placeholder="请输入并选择创建人"></j-search-select-user>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="联系方式">
                <a-input placeholder="请输入联系方式" v-model.trim="queryParam.contactPhone"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" v-has="'ProductLibrarySupplierList:add'">新增</a-button>
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('产品库-供应商')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload> -->
      <!-- 高级查询区域 -->
      <!-- <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange"
        :customRow="selectRowData">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;" :preview="0"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <template slot="nameSlot" slot-scope="text">
          <j-ellipsis :value="text" :length="20"/>
        </template>
        <template slot="categoryFullNameSlot" slot-scope="text">
          <j-ellipsis :value="text" :length="20"/>
        </template>
        <template slot="buyerSlot" slot-scope="text">
          <j-ellipsis :value="text" :length="20"/>
        </template>
        <template slot="supplierStatusSlot" slot-scope="text, record">
          <a-tag :color="getColor(record)" v-if="text">{{ text }}</a-tag>
        </template>
        <template slot="createBySlot" slot-scope="text">
          <j-ellipsis :value="text" :length="20"/>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-has="'ProductLibrarySupplierList:edit'">编辑</a>

          <a-divider type="vertical" v-has="'ProductLibrarySupplierList:edit'" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item v-has="'ProductLibrarySupplierList:delete'">
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
              <!-- 操作日志 -->
              <a-menu-item v-has="'ProductLibrarySupplierList:log'">
                <j-operate-log :id="record.id"></j-operate-log>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <product-library-supplier-modal ref="modalForm" @ok="modalFormOk"></product-library-supplier-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ProductLibrarySupplierModal from './modules/ProductLibrarySupplierModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import { productMixins } from '@/views/productLibrary/mixins/productMixins'
  export default {
    name: 'ProductLibrarySupplierList',
    mixins:[JeecgListMixin, mixinDevice, productMixins],
    components: {
      ProductLibrarySupplierModal
    },
    data () {
      return {
        description: '产品库-供应商管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'供应商代码',
            align:"center",
            dataIndex: 'code'
          },
          {
            title:'供应商名称',
            align:"center",
            dataIndex: 'name',
            scopedSlots: { customRender: 'nameSlot' }
          },
          {
            title:'经营类目',
            align:"center",
            dataIndex: 'categoryFullName',
            scopedSlots: { customRender: 'categoryFullNameSlot' }
          },
          {
            title:'采购员',
            align:"center",
            dataIndex: 'buyer',
            scopedSlots: { customRender: 'buyerSlot' }
          },
          {
            title:'付款方式',
            align:"center",
            dataIndex: 'paymentMethod_dictText'
          },
          // {
          //   title:'90天退款率',
          //   align:"center",
          //   dataIndex: 'ninetyDayRefundRate',
          //   customRender: function (text) {
          //     return !text ? '' : `${text}%`
          //   },
          // },
          // {
          //   title:'2年退款率',
          //   align:"center",
          //   dataIndex: 'twoYearRefundRate',
          //   customRender: function (text) {
          //     return !text ? '' : `${text}%`
          //   },
          // },
          {
            title:'是否滞留可退',
            align:"center",
            dataIndex: 'isRetentionRefund_dictText'
          },
          {
            title:'回货率',
            align:"center",
            dataIndex: 'returnRate',
            customRender: function (text) {
              return !text ? '' : `${text}%`
            },
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'supplierStatus_dictText',
            scopedSlots: { customRender: 'supplierStatusSlot' }
          },
          // {
          //   title:'备注',
          //   align:"center",
          //   dataIndex: 'remark'
          // },
          {
            title:'创建人',
            align:"center",
            dataIndex: 'createBy',
            scopedSlots: { customRender: 'createBySlot' }
          },
          {
            title:'创建日期',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/hzkj-product/product/productLibrary/supplier/list",
          delete: "/hzkj-product/product/productLibrary/supplier/delete",
          deleteBatch: "/hzkj-product/product/productLibrary/supplier/deleteBatch",
          exportXlsUrl: "/hzkj-product/product/productLibrary/supplier/exportXls",
          importExcelUrl: "hzkj-product/product/productLibrary/supplier/importExcel",
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
      this.loadData_('', 'queryMyCategory');
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    provide(){
      return {
        getProjectList: () => this.treeData
      }
    },
    methods: {
      initDictConfig(){
      },
      selectRowData(record,index){
        const that = this
        return {
          on:{
            dblclick:() => {
              // this.handleDetail(record)
            }
          }
        }
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'categoryId',text:'类目',dictCode:''})
        fieldList.push({type:'string',value:'code',text:'代码',dictCode:''})
        fieldList.push({type:'string',value:'name',text:'名称',dictCode:''})
        fieldList.push({type:'int',value:'paymentMethod',text:'付款方式',dictCode:'product_supplier_payment_method'})
        fieldList.push({type:'string',value:'buyer',text:'采购员',dictCode:''})
        fieldList.push({type:'string',value:'contactName',text:'联系人姓名',dictCode:''})
        fieldList.push({type:'string',value:'contactPhone',text:'联系人电话',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'ninetyDayRefundRate',text:'90天退款率',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'twoYearRefundRate',text:'2年退款率',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'returnRate',text:'回货率',dictCode:''})
        fieldList.push({type:'int',value:'supplierStatus',text:'供应商状态',dictCode:'product_supplier_status'})
        fieldList.push({type:'int',value:'isRetentionRefund',text:'是否滞留可退',dictCode:'product_yes_no'})
        fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
        fieldList.push({type:'string',value:'createBy',text:'创建人',dictCode:''})
        fieldList.push({type:'datetime',value:'createTime',text:'创建日期'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>